const {
    generateCompanyName,
    generateUniqueCode,
    getRandomElement,
    generateRandomInteger,
    generateTrainingParams,
    generateRandomLowerCaseString,
    generateRandomIntegerLenght,
    generateSerialNumbers,
    randomUpperCase,
    getRandomRisk,
    getRandomItems,
    getDateRange
} = require('./common/common')
const convertToChinaTime = require('./utils/convertToChinaTime')
const endDate = "2024-03-25T16:00:00.000Z"
const startDate = "2024-03-22T16:00:00.000Z"
// console.log(getDateRange(startDate).startOfDay)
// for (let index = 0; index < 1000; index++) {
    // // console.log(getRandomDateBetween(startDate,endDate),'显示时间:',convertToChinaTime(getRandomDateBetween(startDate,endDate)))
    // let startDate2 = getDateRange(startDate).startOfDay
    // let endDate2 = getDateRange(endDate).endOfDay
    // console.log(index, convertToChinaTime(randomDate(startDate2, endDate2)), convertToChinaTime(startDate2), convertToChinaTime(endDate2))
    // let testTiem = randomDate(startDate, endDate)
    // console.log(testTiem, convertToChinaTime(testTiem))
    console.log(getDatesBetween(startDate, endDate))
// }
function randomDate(startDate, endDate) {
    // 将开始时间和结束时间转换为时间戳
    const startTimestamp = new Date(startDate).getTime()
    const endTimestamp = new Date(endDate).getTime() + (86400000 - 1)

    // 在时间范围内生成随机的时间戳
    const randomTimestamp = startTimestamp + Math.random() * (endTimestamp - startTimestamp)

    // 将随机的时间戳转换为日期对象
    return new Date(randomTimestamp)
}
function getDatesBetween(startDate, endDate) {
    let dateArray = [];
    let currentDate = new Date(startDate);
    let currentEndDate = new Date(endDate);
    if ((!currentDate) || (!currentEndDate)) {
        throw Error()
    }
    while (currentDate <= currentEndDate) {
        dateArray.push(new Date(currentDate));
        currentDate.setDate(currentDate.getDate() + 1);
    }
    return dateArray;
}
function getRandomDateBetween(startDate, endDate) {
    // 将两个日期转换为毫秒数  
    const start = new Date(startDate).getTime();
    const end_tmp = new Date(endDate);
    const end = new Date(end_tmp.getFullYear(), end_tmp.getMonth(), end_tmp.getDate(), 23, 59, 59);
    // 生成一个介于两个日期之间的随机毫秒数  
    const randomMillis = Math.random() * (end - start) + start;
    // 将随机毫秒数转换回Date对象  
    const randomDate = new Date(randomMillis);
    // 确保随机日期不包括endDate（如果需要的话）  
    if (randomDate >= endDate) {
        return new Date(end - 1); // 减去1毫秒以确保不包括endDate本身  
    }
    return randomDate;

} 